package com.anyisn.anyflickr.shell.model
{
	import com.adobe.webapis.flickr.events.FlickrResultEvent;
	
	import com.anyisn.anyflickr.shell.ShellFacade;
	import com.anyisn.anyflickr.shell.model.vo.PhotoListVO;
	import com.anyisn.flickr.as3.patterns.proxy.FlickrPhotosProxy;
	
	public class SlidePhotosProxy extends FlickrPhotosProxy
	{
		public static const NAME:String = 'SlidePhotosProxy';	
			
		public function SlidePhotosProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		override protected function onInterestingnessGetList(event:FlickrResultEvent) : void {
			super.onInterestingnessGetList(event);
			if(event.success) {
				lastList = currentList;
				currentList = new PhotoListVO(ShellFacade.SLIDE_INTERESTINGNESS_GET_LIST, event.data.photos);
				sendNotification(ShellFacade.SLIDE_INTERESTINGNESS_GET_LIST_SUCCESS, currentList);
			} else {
				onFlickrError(event);
				sendNotification(ShellFacade.SLIDE_INTERESTINGNESS_GET_LIST_FAILED);
			}
		}
		
		override protected function onPhotosSearch(event:FlickrResultEvent) : void {
			super.onPhotosSearch(event);
			if(event.success) {
				lastList = currentList;
				currentList = new PhotoListVO(ShellFacade.SLIDE_PHOTOS_SEARCH, event.data.photos);
				currentList.searchVO = searchVO;
				sendNotification(ShellFacade.SLIDE_PHOTOS_SEARCH_SUCCESS, currentList);
			} else {
				onFlickrError(event);
				sendNotification(ShellFacade.SLIDE_PHOTOS_SEARCH_FAILED);
			}
		}
		
		override protected function onPeopleGetPublicPhotos(event:FlickrResultEvent) : void {
			super.onPeopleGetPublicPhotos(event);
			if(event.success) {
				lastList = currentList;
				currentList = new PhotoListVO(ShellFacade.SLIDE_PEOPLE_GET_PUBLIC_PHOTOS, event.data.photos);
				currentList.nsid = nsid;
				sendNotification(ShellFacade.SLIDE_PEOPLE_GET_PUBLIC_PHOTOS_SUCCESS, currentList);
			} else {
				onFlickrError(event);
				sendNotification(ShellFacade.SLIDE_PEOPLE_GET_PUBLIC_PHOTOS_FAILED);
			}
		}
		
		override protected function onGetFavoritesList(event:FlickrResultEvent) : void {
			super.onGetFavoritesList(event);
			if(event.success) {
				lastList = currentList;
				currentList = new PhotoListVO(ShellFacade.SLIDE_FAVORITES_GET_LIST, event.data.photos);
				sendNotification(ShellFacade.SLIDE_FAVORITES_GET_LIST_SUCCESS, currentList);
			} else {
				onFlickrError(event);
				sendNotification(ShellFacade.SLIDE_FAVORITES_GET_LIST_FAILED);
			}
		}
		
		override protected function get perpage() : uint {
			var proxy:SettingsProxy = facade.retrieveProxy(SettingsProxy.NAME) as SettingsProxy;
			return proxy.slidePerpage;
		}
	}
}